using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// <para>
    /// For very large images, you'll need to construct an image pyramid, which is a 
    /// hierarchical set of images, each of which is an increasingly lower resolution 
    /// version of the original image. Each image in the pyramid is subdivided into tiles, so 
    /// that only the portions in view need to be loaded. Google Earth calculates the current 
    /// viewpoint and loads the tiles that are appropriate to the user's distance from the image. 
    /// As the viewpoint moves closer to the PhotoOverlay, Google Earth loads higher resolution tiles. 
    /// Since all the pixels in the original image can't be viewed on the screen at once, this 
    /// preprocessing allows Google Earth to achieve maximum performance because it loads only 
    /// the portions of the image that are in view, and only the pixel details that can be discerned 
    /// by the user at the current viewpoint.
    /// </para>
    /// <para>
    /// When you specify an image pyramid, you also modify the href in the Icon element 
    /// to include specifications for which tiles to load.
    /// </para>
    /// </summary>
    public class KmlImagePyramid : IKmlElement
    {
        private string tagName = "ImagePyramid";

        #region TileSize
        private int tileSize = 256;

        /// <summary>
        /// Size of the tiles, in pixels. Tiles are square. A tile size of 256 (the default) or 512 is recommended. 
        /// The original image is divided into tiles of this size, at varying resolutions. 
        /// </summary>
        /// <value>The size of the tile.</value>
        public int TileSize
        {
            get { return tileSize; }
            set { tileSize = value; }
        } 
        #endregion

        #region Width
        private int width;

        /// <summary>
        /// Gets or sets the width in pixels of the original image. 
        /// </summary>
        /// <value>The width.</value>
        public int Width
        {
            get { return width; }
            set { width = value; }
        } 
        #endregion

        #region Height
        private int height;

        /// <summary>
        /// Gets or sets the height in pixels of the original image
        /// </summary>
        /// <value>The height.</value>
        public int Height
        {
            get { return height; }
            set { height = value; }
        } 
        #endregion

        #region IKmlElement Members

        /// <summary>
        /// Name of the KML tag for this specific element.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        public string TagName
        {
            get { return tagName; }
        }

        #endregion

        #region IKmlGenerator Members

        public void GenerateKml(System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartElement(this.tagName);
            writer.WriteElementString("tileSize", this.tileSize.ToString());
            writer.WriteElementString("width", this.width.ToString());
            writer.WriteElementString("height", this.height.ToString());
            writer.WriteFullEndElement();
        }

        #endregion
    }
}
